<template>
  <div>
    <StatisticsComponent :isZJC="userInfo.userName === 'zhoujinchuan'"/>
    <el-tabs v-model="activeTab" class="tableData">
      <el-tab-pane label="我的申请" name="myApplication">
        <InstanceTable v-if="activeTab == 'myApplication'" :type="'1'"/>
      </el-tab-pane>
      <el-tab-pane label="我的待办" name="myAgent">
        <InstanceTable v-if="activeTab == 'myAgent'" :type="'2'"/>
      </el-tab-pane>
      <el-tab-pane label="我的已办" name="myDone">
        <InstanceTable v-if="activeTab=='myDone'" :type="'3'"/>
      </el-tab-pane>
    </el-tabs>

  </div>
</template>

<script>
import StatisticsComponent from "@/components/StatisticsComponent"; // 导入统计组件
import InstanceTable from "@/components/InstanceTable"; // 导入表组件
import request from "@/request/request";

export default {
  data() {
    return {
      userInfo: {
        id: 1,
        nickName: "周进川",
        password: "123456",
        userName: "zhoujinchuan"
      },
      activeTab: "myApplication", // 默认选中的标签页
    };
  },
  created() {
    // 在 created 钩子中尝试获取 token
    const token = sessionStorage.getItem("token");
    if (token) {
      // 尝试获取用户数据
      request.get("/getmine")
          .then((response) => {
            if (response.code === 200) {
              this.userInfo = response.data;
            } else {
              this.$router.push("/");
            }
          });
    } else {
      // 如果 token 不存在，跳转到登录页面
      this.$router.push("/");
    }
  },
  components: {
    StatisticsComponent,
    InstanceTable
  },
  methods: {
    logout() {
      // 实现退出登录逻辑
      // 跳转到登录页面
      this.$router.push("/");
    }, handleSearch() {
      // 处理搜索
      // const search = this.searchText.toLowerCase();
      // this.tableData = this.originalData.filter((item) => {
      //   return item.name.toLowerCase().includes(search) || item.id.toString().includes(search);
      // });
    }
  },
};
</script>

<style scoped>
.tableData {
  background-color: #ffffff;
  padding: 50px;
  border-radius: 5px;
}
</style>
